home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS / antlr / generic.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-14  |  5.9 KB  |  196 lines  |  [TEXT/MPS ]

  1. /*
  2.  * generic.h -- generic include stuff for new PCCTS ANTLR.
  3.  *
  4.  * $Id: generic.h,v 1.8 1994/08/29 20:16:14 parrt Exp parrt $
  5.  * $Revision: 1.8 $
  6.  *
  7.  * SOFTWARE RIGHTS
  8.  *
  9.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  10.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  11.  * company may do whatever they wish with source code distributed with
  12.  * PCCTS or the code generated by PCCTS, including the incorporation of
  13.  * PCCTS, or its output, into commerical software.
  14.  * 
  15.  * We encourage users to develop software with PCCTS.  However, we do ask
  16.  * that credit is given to us for developing PCCTS.  By "credit",
  17.  * we mean that if you incorporate our source code into one of your
  18.  * programs (commercial product, research project, or otherwise) that you
  19.  * acknowledge this fact somewhere in the documentation, research report,
  20.  * etc...  If you like PCCTS and have developed a nice tool with the
  21.  * output, please mention that you developed it using PCCTS.  In
  22.  * addition, we ask that this header remain intact in our source code.
  23.  * As long as these guidelines are kept, we expect to continue enhancing
  24.  * this system and expect to make other tools available as they are
  25.  * completed.
  26.  *
  27.  * ANTLR 1.23
  28.  * Terence Parr
  29.  * Parr Research Corporation
  30.  * with Purdue University and AHPCRC, University of Minnesota
  31.  * 1989-1994
  32.  */
  33.  
  34. #define StrSame            0
  35.  
  36. #define DefaultParserName    "zzparser"
  37.  
  38. #define ZZLEXBUFSIZE 4000
  39.  
  40. /* Tree/FIRST/FOLLOW defines -- valid only after all grammar has been read */
  41. #define ALT            TokenNum+1
  42. #define SET            TokenNum+2
  43. #define TREE_REF    TokenNum+3
  44.  
  45.                     /* E r r o r  M a c r o s */
  46.  
  47. #define fatal(err)    fatalFL(err, __FILE__, __LINE__)
  48. #define fatal_internal(err)    fatal_intern(err, __FILE__, __LINE__)
  49.  
  50.  
  51. #define eMsg1(s,a)    eMsg3(s,a,NULL,NULL)
  52. #define eMsg2(s,a,b)    eMsg3(s,a,b,NULL)
  53.  
  54.                 /* S a n i t y  C h e c k i n g */
  55.  
  56. #ifndef require
  57. #define require(expr, err) {if ( !(expr) ) fatal_internal(err);}
  58. #endif
  59.  
  60.                     /* L i s t  N o d e s */
  61.  
  62. typedef struct _ListNode {
  63.             void *elem;            /* pointer to any kind of element */
  64.             struct _ListNode *next;
  65.         } ListNode;
  66.  
  67. /* Define a Cycle node which is used to track lists of cycles for later
  68.  * reconciliation by ResolveFoCycles().
  69.  */
  70. typedef struct _c {
  71.             int croot;            /* cycle root */
  72.             set cyclicDep;        /* cyclic dependents */
  73.             unsigned deg;        /* degree of FOLLOW set of croot */
  74.         } Cycle;
  75.  
  76. typedef struct _e {
  77.             int tok;            /* error class name == TokenStr[tok] */
  78.             ListNode *elist;    /* linked list of elements in error set */
  79.             set eset;
  80.             int setdeg;            /* how big is the set */
  81.             int lexclass;        /* which lex class is it in? */
  82.         } ECnode;
  83.  
  84. typedef struct _TCnode {
  85.             int tok;            /* token class name */
  86.             ListNode *tlist;    /* linked list of elements in token set */
  87.             set tset;
  88.             int lexclass;        /* which lex class is it in? */
  89.         } TCnode;
  90.  
  91. typedef struct _ft {
  92.             char *token;        /* id of token type to remap */
  93.             int tnum;            /* move token type to which token position */
  94.         } ForcedToken;
  95.  
  96. #define newListNode    (ListNode *) calloc(1, sizeof(ListNode));
  97. #define newCycle    (Cycle *) calloc(1, sizeof(Cycle));
  98. #define newECnode    (ECnode *) calloc(1, sizeof(ECnode));
  99. #define newTCnode    (TCnode *) calloc(1, sizeof(TCnode));
  100.  
  101.  
  102.                 /* H a s h  T a b l e  E n t r i e s */
  103.  
  104. typedef struct _t {                /* Token name or expression */
  105.             char *str;
  106.             struct _t *next;
  107.             int token;            /* token number */
  108.             unsigned char classname;    /* is it a err/tok class name or token */
  109.             TCnode *tclass;        /* ptr to token class */
  110.             char *action;
  111.         } TermEntry;
  112.  
  113. typedef struct _r {                /* Rule name and ptr to start of rule */
  114.             char *str;
  115.             struct _t *next;
  116.             int rulenum;        /* RulePtr[rulenum]== ptr to RuleBlk junction */
  117.             int noAST;            /* gen AST construction code? (def==gen code) */
  118.             char *egroup;        /* which error group (err reporting stuff) */
  119.         } RuleEntry;
  120.  
  121. typedef struct _f {                /* cache Fi/Fo set */
  122.             char *str;            /* key == (rulename, computation, k) */
  123.             struct _f *next;
  124.             set fset;            /* First/Follow of rule */
  125.             set rk;                /* set of k's remaining to be done after ruleref */
  126.             int incomplete;        /* only w/FOLLOW sets.  Use only if complete */
  127.         } CacheEntry;
  128.  
  129. #define newTermEntry(s)        (TermEntry *) newEntry(s, sizeof(TermEntry))
  130. #define newRuleEntry(s)        (RuleEntry *) newEntry(s, sizeof(RuleEntry))
  131. #define newCacheEntry(s)    (CacheEntry *) newEntry(s, sizeof(CacheEntry))
  132.  
  133.  
  134. typedef struct _UserAction {
  135.             char *action;
  136.             int file, line;
  137.         } UserAction;
  138.  
  139.  
  140.                     /* L e x i c a l  C l a s s */
  141.  
  142. /* to switch lex classes, switch ExprStr and Texpr (hash table) */
  143. typedef struct _lc {
  144.             char *classnum, **exprs;
  145.             Entry **htable;
  146.         } LClass;
  147.  
  148. typedef struct _exprOrder {
  149.             char *expr;
  150.             int lclass;
  151.         } Expr;
  152.  
  153.  
  154. typedef Graph Attrib;
  155.  
  156.                         /* M a x i m u m s */
  157.  
  158. #ifndef HashTableSize
  159. #define HashTableSize    253
  160. #endif
  161. #ifndef StrTableSize
  162. #define StrTableSize    15000    /* all tokens, nonterminals, rexprs stored here */
  163. #endif
  164. #define MaxLexClasses    50        /* how many automatons */
  165. /* TokenStart and EofToken are ignored if #tokdefs meta-op is used */
  166. #define TokenStart        2        /* MUST be in 1 + EofToken */
  167. #define EofToken        1        /* Always predefined to be 1 */
  168. #define MaxNumFiles        20
  169. #define MaxFileName        300        /* largest file name size */
  170. #define MaxRuleName        100        /* largest rule name size */
  171. #define TSChunk            100        /* how much to expand TokenStr/ExprStr each time */
  172. #define TIChunk            TSChunk    /* expand TokenInd by same as TokenStr to mirror them */
  173. #define FoStackSize        100        /* deepest FOLLOW recursion possible */
  174.  
  175. /* AST token types */
  176. #define ASTexclude        0
  177. #define ASTchild        1
  178. #define ASTroot            2
  179. #define ASTinclude        3        /* include subtree made by rule ref */
  180.  
  181.  
  182. #define PredictionVariable                "zzpr_expr"
  183. #define PredictionLexClassSuffix        "_zzpred"
  184.  
  185. #ifndef ANTLRm
  186. #define ANTLRm(st, f, _m)    zzbufsize = ZZLEXBUFSIZE;\
  187.                         zzmode(_m);                    \
  188.                         zzenterANTLR(f);            \
  189.                         st; ++zzasp;                \
  190.                         zzleaveANTLR(f);
  191. #endif                        
  192.  
  193. #include "proto.h"
  194. #include "config.h"
  195. #include <string.h>
  196.